import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { UserInfoVO } from "@/types/user";

export default defineStore('userInfo', () => {
  const userInfo = ref<{ phone: string } & UserInfoVO | null>(null)
  const setUserInfo = (val: UserInfoVO, phone: string) => userInfo.value = { phone, ...val}
  const updateUserInfo = (val: { avatar: string | null, nickname: string }) => Object.assign(userInfo.value!, val)
  return { userInfo, setUserInfo, updateUserInfo }
}, {
  persist: {
    storage: {
      getItem: key => uni.getStorageSync(key),
      setItem: (key, value) => uni.setStorageSync(key, value)
    }
  }
})